import cv2
import numpy as np

all_img = cv2.imread('3h3m.png')
all_img = cv2.cvtColor(all_img, cv2.COLOR_BGR2GRAY)
template = cv2.imread('3.jpeg', 0)
h, w = template.shape[:2]

res = cv2.matchTemplate(all_img, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.7 # 取匹配程度大于%70的坐标

loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):  # *号表示可选参数
    bottom_right = (pt[0] + w, pt[1] + h)
    cv2.rectangle(all_img, pt, bottom_right, (0, 0, 255), 2)

cv2.imshow('img_rgb', all_img)
cv2.waitKey(0)
